package com.rapida.pet.core;

public class PetBehavie {
	public enum PetState {
		P1,P2,P3,P4,P5
	};

	public enum Event {
		E1,E2,E3,E4,E5
	};

	public interface IStateChangedSlot {
		void stateChangedSlot(PetState v);
	}

	private IStateChangedSlot mIState;
	private StateMachine<PetState, Event> sm;

	public PetBehavie() {
		sm = new StateMachine<PetState, Event>(PetState.P1);
		sm.append(PetState.P2, Event.E1, PetState.P1);
		sm.append(PetState.P3, Event.E1, PetState.P1);
		sm.append(PetState.P4, Event.E1, PetState.P1);
		sm.append(PetState.P5, Event.E1, PetState.P1);
		sm.append(PetState.P1, Event.E2, PetState.P2);
		sm.append(PetState.P1, Event.E3, PetState.P3);
		sm.append(PetState.P1, Event.E4, PetState.P4);
		sm.append(PetState.P1, Event.E5, PetState.P5);
	}

	public void setCurrentState(PetState state) {
		sm.setCurrentState(state);
	}

	public void trigerEvent(Event event) {
		if (sm.eventTriger(event)) {
			if (mIState != null) {
				mIState.stateChangedSlot(sm.currentState());
			}
		}
	}

	public void registerEvent(IStateChangedSlot iscs) {
		mIState = iscs;
	}
}
